package com.cn.kabalifeuser.ui.my.activity;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.cn.kabalifeuser.R;
import com.cn.kabalifeuser.base.IBaseActivity;
import com.cn.kabalifeuser.config.LoginHelper;
import com.cn.kabalifeuser.ui.login.bean.MsgBean;
import com.cn.kabalifeuser.ui.my.bean.AppVersionBean;
import com.cn.kabalifeuser.ui.my.bean.MyUserInfoBean;
import com.cn.kabalifeuser.ui.my.bean.UpImgBean;
import com.cn.kabalifeuser.utils.MyAnimationError;
import com.cn.kabalifeuser.utils.RxToast;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by 晓林 on 2020/7/7.
 * function:
 */
public class UserInfoNameActivity extends IBaseActivity<UserInfoView, UserInfoPresenter> implements UserInfoView {


    @BindView(R.id.et_name)
    EditText etName;

    Bundle bundle;
    String name;

    @Override
    protected UserInfoPresenter createPresenter() {
        return new UserInfoPresenter();
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_userinfo_name;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        super.initView(savedInstanceState);
        bundle = getIntent().getExtras();
        name = bundle.getString("name");
        setTitleBar("修改昵称");
        etName.setText(name);
    }


    @Override
    public void onReLoggedIn(String msg) {

        RxToast.error(msg);
        LoginHelper.againGoToLoginActivity(getMe());
    }

    @Override
    public void onError(String msg) {
        RxToast.error(msg);
    }

    @Override
    public Context _getContext() {
        return getMe();
    }

    @Override
    public void onUpImgSuccess(UpImgBean bean) {

    }

    @Override
    public void onUpUserInfoSuccess(MsgBean bean) {
        RxToast.success(bean.getMsg());
        finish();
    }

    @Override
    public void onUserInfoSuccess(MyUserInfoBean bean) {

    }

    @Override
    public void onUserOutSuccess(MsgBean bean) {

    }

    @Override
    public void onAppVersionSuccess(AppVersionBean bean) {

    }


    @OnClick({R.id.tv_all, R.id.tv_btn_next})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_all:
                hideKeyboard(etName);
                break;
            case R.id.tv_btn_next:
                if (!TextUtils.isEmpty(etName.getText().toString().trim())) {
                    mPresenter.onUpUserInfoNameData(LoginHelper.getLonginData().getResult(), etName.getText().toString().trim());
                } else {
                    MyAnimationError.ErrorAnimation(this, etName);
                    RxToast.error("昵称不可为空");
                }
                break;
        }
    }
}

